define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'centralcontact_project/index' + location.search,
                    add_url: 'centralcontact_project/add',
                    edit_url: 'centralcontact_project/edit',
                    del_url: 'centralcontact_project/del',
                    multi_url: 'centralcontact_project/multi',
                    table: 'centralcontact_project',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name')},

                        {field: 'investment_total', title: __('Investment_total')},
                        {field: 'access_time', title: __('Access_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'access_time_desc', title: __('Access_time_desc')},
                        {field: 'sign_time', title: __('Sign_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'sign_time_desc', title: __('Sign_time_desc')},
                        {field: 'investment_area', title: __('Investment_area')},
                        {field: 'register_time', title: __('Register_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'register_time_desc', title: __('Register_time_desc')},
                        {field: 'chargedep_ids', title: __('Chargedep_ids')},
                        {field: 'chargedep_names', title: __('Chargedep_names')},
                        {field: 'settle_street_ids', title: __('Settle_street_ids')},
                        {field: 'settle_street_names', title: __('Settle_street_names')},
                        {field: 'receive_time', title: __('Receive_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'receive_time_desc', title: __('Receive_time_desc')},
                        {field: 'leader_ids', title: __('Leader_ids')},
                        {field: 'leader_names', title: __('Leader_names')},
                        {field: 'centraloffice_id', title: __('Centraloffice_id')},
                        {field: 'centraloffice_name', title: __('Centraloffice_name')},
                        {field: 'state', title: __('State')},
                        {field: 'stop_reason', title: __('Stop_reason')},
                        {field: 'stop_time', title: __('Stop_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'framework_agreement_time', title: __('Framework_agreement_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'invesment_agreement_time', title: __('Invesment_agreement_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'start_construction_time', title: __('Start_construction_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operation_time', title: __('Operation_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'contact_name', title: __('Contact_name')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});